package com.yd.app.mapper;

import com.yd.app.mapper.provider.EvaluateProvider;
import com.yd.domain.business.Evaluate;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 评价Mapper
 * Created by sunxianhui on 2018/3/9.
 */
@Repository
public interface EvaluateMapper {

    /**
     * 添加评价
     * @param evaluate
     */
    @Insert("insert into business_evaluate (id,orderId,goodsId,content,publishUser,publishTime) values (#{evaluate.id},#{evaluate.orderId},#{evaluate.goodsId},#{evaluate.content},#{evaluate.publishUser},#{evaluate.publishTime})")
    int addEvaluate(@Param("evaluate") Evaluate evaluate);

    /**
     * 修改
     * @param evaluate
     */
    @Update("update business_evaluate set goodsId=#{evaluate.goodsId},content=#{evaluate.content},publishUser=#{evaluate.publishUser},publishTime=#{evaluate.publishTime} where id=#{evaluate.id}")
    int updateEvaluate(@Param("evaluate") Evaluate evaluate);

    /**
     * 删除
     * @param id
     */
    @Delete("delete from business_evaluate where id=#{id}")
    int deleteEvaluateById(@Param("id") String id);

    /**
     * 查找
     * @param goodsId
     * @param orderId
     */
    @Select("select * from business_evaluate where orderId=#{orderId} and goodsId=#{goodsId} ")
    Evaluate getEvaluate(@Param("orderId") String orderId,@Param("goodsId") String goodsId);

    /**
     * 根据条件分页查询
     * @param goodsId
     * @param startRow
     * @param pageSize
     * @return
     */
    @SelectProvider(method = "searchEvaluateList", type = EvaluateProvider.class)
    List<Evaluate> getEvaluateList(@Param("goodsId") String goodsId, @Param("startRow") int startRow, @Param("pageSize") int pageSize);

    /**
     * 根据条件查询数量
     * @param goodsId
     * @return
     */
    @SelectProvider(method = "searchEvaluateCount", type = EvaluateProvider.class)
    int getEvaluateCount(@Param("goodsId") String goodsId);
    @Delete("delete from business_evaluate where orderId=#{orderId} AND goodsId=#{goodsId}")
    void deleteEvaluate(@Param("orderId")String orderId,@Param("goodsId") String goodsId);
}
